



#ifndef _PDF_BARCODE_H_
#define _PDF_BARCODE_H_

#include <wx/string.h>

#include "wx/pdfdocdef.h"

// Forward declarations
class WXDLLIMPEXP_FWD_PDFDOC wxPdfDocument;

const wxChar CODE128_FNC1 = 0xf1;
const wxChar CODE128_FNC3 = 0xf2;
const wxChar CODE128_FNC2 = 0xf3;
const wxChar CODE128_FNC4 = 0xf4;


class WXDLLIMPEXP_PDFDOC wxPdfBarCodeCreator
{
public:
  /// Constructor
  
  wxPdfBarCodeCreator(wxPdfDocument& document);

  /// Destructor
  virtual ~wxPdfBarCodeCreator();

  /// Draw a EAN13 barcode
  
  bool EAN13(double x, double y, const wxString& barcode, double h = 16, double w = .35);

  /// Draw a UPC-A barcode
  
  bool UPC_A(double x, double y, const wxString& barcode, double h = 16, double w = .35);

  /// Draw standard or extended Code39 barcode
  
  bool Code39(double x, double y, const wxString& code, bool ext = true, bool cks = false, double w = 0.4, double h = 20, bool wide = true);

  /// Draw an Interleaved 2 of 5 barcode
  
  bool I25(double xpos, double ypos, const wxString& code, double basewidth = 1, double height = 10);

  /// Draw U.S. Postal Service POSTNET barcodes
  
  bool PostNet(double x, double y, const wxString& zipcode);

  /// Draw a Code128 barcode automatically switching the code sets as needed
  
  bool Code128(double x, double y, const wxString& barcode, double h, double w = 0.21);

  /// Draw a Code128 barcode using only code set A
  
  bool Code128A(double x, double y, const wxString& barcode, double h = 13, double w = 0.21);

  /// Draw a Code128 barcode using only code set B
  
  bool Code128B(double x, double y, const wxString& barcode, double h = 13, double w = 0.21);

  /// Draw a Code128 barcode using only code set C
  
  bool Code128C(double x, double y, const wxString& barcode, double h = 13, double w = 0.21);

  /// Draw a EAN128 barcode
  
  bool EAN128(double x, double y, const wxString& barcode, double h, double w = 0.21);

protected:
  /// Calculate check digit
  wxChar GetCheckDigit(const wxString& barcode);

  /// Validate check digit
  bool TestCheckDigit(const wxString& barcode);

  /// Draw a barcode
  bool Barcode(double x, double y, const wxString& barcode, double h, double w, unsigned int len);

  /// Encode extended Code39 barcode
  wxString EncodeCode39Ext(const wxString& code);

  /// Calculate Code39 check sum
  wxChar ChecksumCode39(const wxString& code);

    void DrawCode39(const wxString& code, double x, double y, double w, double h);

  /// Validate ZIP code
  bool ZipCodeValidate(const wxString& zipcode);

  /// Calculate ZIP code check sum digit
  int ZipCodeCheckSumDigit(const wxString& zipcode);

    void ZipCodeDrawDigitBars(double x, double y, double barSpacing,
                            double halfBarHeight, double fullBarHeight, int digit);

    void Code128Draw(double x, double y, const wxString& barcode, double h, double w);

private:
  wxPdfDocument* m_document;  ///< Document this barcode creator belongs to
};

#endif
